import json
import os


class Fession(object):
    def __init__(self):
        pass
    def setFassion(self, name, value=0,add=0):
        print(name,value,add)
        FessionFile = open('Fession.json', 'a+',encoding='utf-8')
        FessionFile.tell()
        # 输出当前指针位置
        FessionFile.seek(os.SEEK_SET)
        # 设置指针回到文件最初
        items = json.load(FessionFile)
        if add == 0:
            items[0][name] = value
        else:
            items[0][name] = items[0][name] + add
        FessionFile.seek(0)
        FessionFile.truncate()
        json.dump(items, FessionFile, ensure_ascii=False)
        FessionFile.close()


    def getFassion(self, name):
        FessionFile = open('Fession.json', 'r', encoding='utf-8')
        setting = json.load(FessionFile)
        print(setting)
        FessionFile.close()
        return setting[0][name]


if __name__ == "__main__":
    obj_spider = Fession()
    obj_spider.setFassion("indexCount",value=123)